import VueI18n from 'vue-i18n'

import ElementEN from 'element-ui/lib/locale/lang/en'
import ElementZhCN from 'element-ui/lib/locale/lang/zh-CN'
import ElementLocale from 'element-ui/lib/locale'

import 'xe-utils'
import VxeTable from 'vxe-table'
import 'vxe-table/lib/style.css'
import VxeEN from 'vxe-table/lib/locale/lang/en-US'
import VxeZhCN from 'vxe-table/lib/locale/lang/zh-CN'

import VueCropper from 'vue-cropper'

export const install = function (Vue, opts = {}) {
    Vue.use(VueI18n)

    const i18n = function (messages) {
        const _i18n = new VueI18n({
            locale: opts.locale || 'zh_CN',
            messages: Object.keys(messages).reduce((ins, key) => {
                ins[key] = {...messages[key]}
                return ins
            }, {})
        })

        return (key, value) => _i18n.t(key, value)
    }

    Vue.prototype.$ELEMENT = {
        size: opts.size,
        zIndex: opts.zIndex || 2000
    }

    ElementLocale.i18n(i18n({en: ElementEN, zh_CN: ElementZhCN}))

    Vue.use(VxeTable, {
        size: opts.size,
        i18n: i18n({en: VxeEN, zh_CN: VxeZhCN})
    })

    VxeTable.setup({
        pager: {
            pageSizes: [10, 15, 20, 50, 100]
        }
    })

    Vue.use(VueCropper)
}

export default install